//第一步：引入api接口
import { reqCategoryList, reqGetBannerList, reqGetFloorList } from '@/api'

//home模块的小仓库
const state = {
    //state中的数据别瞎写，服务器返回的是一个对象就建一个空对象（数组就建一个空数组）。
    //存储三级菜单的数据
    categoryList: [],
    //banner轮播图的数据
    bannerList: [],
    //floor轮播图的数据
    floorList: []
}
const mutations = {
    //第四步：计算好数据传给state
    CATEGORYLIST(state, categoryList) {
        state.categoryList = categoryList;
    },
    GETBANNERLIST(state, bannerList) {
        state.bannerList = bannerList;
    },
    GETFLOORLIST(state, floorList) {
        state.floorList = floorList;
    }
}
const actions = {
    //第二步：通过API里面的接口函数调用，向服务器发送请求，获取服务器的数据
    async categoryList({ commit }) {
        let result = await reqCategoryList();
        if (result.code == 200) {

            //第三步：数据传给属性mutations
            commit("CATEGORYLIST", result.data);
        }
    },

    // 获取mock首页轮播图的数据
    async getBannerList({ commit }) {
        let result = await reqGetBannerList();
        if (result.code == 200) {
            commit('GETBANNERLIST', result.data)

        }
    },
    //获取floor楼层轮播图数据库
    async getFloorList({ commit }) {
        let result = await reqGetFloorList();
        if (result.code == 200) {
            commit('GETFLOORLIST', result.data)
        }
    }
}
const getters = {}

//对外暴露
export default {
    state,
    mutations,
    actions,
    getters
}